<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>拖车业务管理</title>

    <!-- 自定义style -->
    <style>
        .clean {
            clear: both
        }

        .dataTB {
            width: 100%;
            /* border: 1px solid #8F8888; */
            line-height: 20px;
            font-size: 10px;
        }

        td.dataTD {
            /* font-weight: bold; */
            text-align: left;
            /* 	border: 1px solid #8F8888; */
            /* 	white-space: nowrap; */
        }

        .labelTD_1 {
            /*background-color: #DFF0F8;*/
            width: 100px;
            text-align: right;
            /* border-left: 1px solid #8D8E97; */
            font-size: 12px
        }

        .custom_trailer {
            border: none;
            padding: 0px;
        }

        .custom_supplier {
            border: 1px solid #d7dbdc;
            border-radius: 6px;
            width: 100%;
        }

        .table_header {
            widht: 100%;
        }

        .labelTD_first {
            width: 100px;
            text-align: right;
        }

        .labelTD_two {
            width: 60%;
        }

        th {
            line-height: 24px;
            text-align: left;
            padding-left: 10px;
        }

        table {
            border-collapse: separate;
            font-family: "微软雅黑"
            font-size: 12px
        }

        tr {
            width: 100%;
            line-height: 24px;
        }

        .table_box {
            padding-left: 10px;
        }

        .custom_btn {
            padding: 5px 10px;
        }

        .custom_btnss {
            padding: 3px 10px;
        }

        .labelTD_12 {
            border-right: 1px solid #d7dbdc;
            border-bottom: 1px solid #d7dbdc;
        }

        .labelTD_1 {
            padding-left: 5px
        }
    </style>
    <!-- 自定义style -->
    <!-- 自定义script -->
    <script type="text/javascript">
        $(function () {
            var checkType = $("#checkTypeInput").val();
            if (checkType == "C") {
                $("#customInfo").show();
            } else {
                $("#supInfo").show();
            }

            initFuncButton();
            var identifyTrail = $("#identifyForSup").val();
            if ("checkDetailForSup" == identifyTrail) {
                $("#bizModifyBtn").hide();
                $("#bizConfirmBtn").hide();
            } else {
                $("#trailVpassBtn").hide();
                $("#trailVrejectBtn").hide();
            }
        });

        function initFuncButton() {
            $("button").attr("disabled", true);
            var trailState = "${trail.trailState}";
            if (trailState == "TS00" || trailState == "TS03") {//草稿、驳回
                $("#bizModifyBtn").attr("disabled", false);
                $("#bizConfirmBtn").attr("disabled", false);
            }
            if (trailState == "TS01") {//待审核
                $("#trailVpassBtn").attr("disabled", false);
                $("#trailVrejectBtn").attr("disabled", false);
            }
            $("#returnBtn").attr("disabled", false);
            $("#createExlBtn").attr("disabled", false);
            $("#createExlBtn1").attr("disabled", false);
        }

        function bizModify() {
            var id = "${trail.id}";
            var data = "id=" + id;
            $.ajax({
                       url: "trail-checkBizModify",
                       dataType: "json",
                       data: data,
                       success: function (data) {
                           if (!data) {
                               return;
                           }
                           var msg = data.msg ? $.parseJSON(data.msg) : "";
                           if (msg.state == 1) {
                               jw.confirm("确定要修改该业务?", function () {
                                   //jw.alert($.parseJSON(data.msg).msg);
                                   //window.location.href="trail-bizModify?id="+id;
                                   window.location.href = "business-updateSingle?id="
                                                          + id + "&singleType=C";
                               }, function () {
                                   return;
                               });
                           }
                           else if (msg !== undefined && msg != "" && msg.state == 0) {

                               jw.alert("只有处于草稿和驳回状态的业务才可以修改。");
                           } else {
                               jw.alert(msg.msg);
                           }
                       }
                   });
        }

        function bizConfirm() {
            var id = "${trail.id}";
            var iddata = "id=" + id;
            $.ajax({
                       url: "trail-checkBizConfirm",
                       dataType: "json",
                       data: iddata,
                       success: function (data) {
                           if (!data) {
                               return;
                           }
                           var msg = data.msg ? $.parseJSON(data.msg) : "";
                           if (msg.state == 1) {
                               jw.confirm("确定要提交该业务?", function () {
                                   $.ajax({
                                              url: "trail-bizConfirm",
                                              dataType: "json",
                                              data: iddata,
                                              success: function (data) {
                                                  jw.alert($.parseJSON(data.msg).msg, {
                                                      onOk: function () {
                                                          window.location.href = "trail-main";
                                                      }
                                                  });
                                              }
                                          });
                               }, function () {
                                   return;
                               });
                           }
                           else if (msg !== undefined && msg != "" && msg.state == 0) {
                               jw.alert("只有处于草稿和驳回状态的业务才可以提交。");
                           } else {
                               jw.alert(msg.msg);
                           }
                       }
                   });
        }

        function queryByCn(carMsgId) {
            if (carMsgId != null || carMsgId == undefined) {
                // 		location.href = "business-queryByCn?carMsgId="+carMsgId;
                jw.dialog({
                              iframe: '../business/business-queryByCn?carMsgId='
                                      + carMsgId,
                              title: "拖车出入闸信息",
                              iframeFetchTitle: false,
                              width: 200
                          });
            }
        }

        function checkGoodGw(containerNo, containerId, st) {
            if (containerNo == null || containerNo == "") {
                alert("暂时没有毛重!");
            } else {
                var data = "id=" + containerId + "&containerNo=" + containerNo;
                $.ajax({
                           url: "business-checkGoodGw",
                           cache: false,
                           dateType: "json",
                           data: data,
                           success: function (data) {
                               var goodGw = data.goodGw;
                               if (!goodGw) {
                                   goodGw = "暂无毛重信息!";
                               }

                               var checkGoodGwId = "#checkGoodGw_" + st;
                               $(checkGoodGwId).text(goodGw);
                           }
                       });
            }

        }
        /**
         * 查看详细页面的返回按钮触发的方法
         */
        function trailDetailReturnBack() {
            var identify = $("#identifyForSup").val();
            if ("checkDetailForSup" == identify) {
                location.href = "trail-listForSupToValidate";
            } else {
                location.href = "trail-main";
            }
        }
        /**
         * 审核通过
         */
        function validatePass() {
            $("#trailVpassBtn").attr("disabled", true);
            $("#trailVrejectBtn").attr("disabled", true);
            var id = "${trail.id}";

            var iddata = "id=" + id + "&opType=tgsh";
            $
                    .ajax({
                              url: "trail-checkValidatePass",
                              dataType: "json",
                              data: iddata,
                              success: function (data) {
                                  if (!data) {
                                      return;
                                  }
                                  var msg = data.msg ? $.parseJSON(data.msg) : "";
                                  if (msg.state == 1) {
                                      jw
                                              .confirm(
                                                      "确定要该业务通过审核?",
                                                      function () {
                                                          $
                                                                  .ajax({
                                                                            url: "trail-validatePass",
                                                                            dataType: "json",
                                                                            data: iddata,
                                                                            success: function (data) {
                                                                                jw
                                                                                        .alert(msg.msg,
                                                                                               {
                                                                                                   onOk: function () {
                                                                                                       // 											window.location.href="trail-listForSupToValidate";
                                                                                                       window.location.href =
                                                                                                               "trail-findForSupToValidate?id="
                                                                                                               + id
                                                                                                               + "&identify=checkDetailForSup";
                                                                                                   }
                                                                                               });
                                                                            }
                                                                        });
                                                      }, function () {
                                                          return;
                                                      });
                                  } else if (msg !== undefined && msg != "" && msg.state == 0) {
                                      jw.alert("只有处于待审核状态的业务才可以进行审核操作。");
                                  } else {
                                      jw.alert(msg.msg);
                                  }
                              }
                          });
        }
        /**
         * 拖车驳回
         */
        function validateReject() {
            var id = "${trail.id}";

            var iddata = "id=" + id + "&opType=bh";
            $.ajax({
                       url: "trail-checkValidatePass",
                       dataType: "json",
                       data: iddata,
                       success: function (data) {
                           if (!data) {
                               return;
                           }
                           var msg = data.msg ? $.parseJSON(data.msg) : "";
                           if (msg.state == 1) {
                               jw.confirm("确定要驳回该业务?", function () {
                                   jw.dialog({
                                                 iframe: '../business/rejectContent-reject?id='
                                                         + id + "&type=2",
                                                 title: "驳回",
                                                 iframeFetchTitle: false,
                                                 width: 600,
                                                 height: 150
                                             });
                               }, function () {
                                   return;
                               });
                           }
                           else if (msg !== undefined && msg != "" && msg.state == 0) {
                               jw.alert("只有处于待审核状态的业务才可以进行驳回业务操作。");
                           } else {
                               jw.alert(msg.msg);
                           }
                       }
                   });
        }

        /**
         * 导出拖车委托单
         */
        function createExl() {
            var id = "${trail.id}";
            // 	var url = "http://localhost:8075/WebReport/ReportServer?reportlet=trail.cpt&id="+id+"";
            var url = "http://219.130.222.62:7080/report/ReportServer?reportlet=gtimp/trail.cpt&id="
                      + id + "";
            window.open(url);
        }

        /**
         * 内网用户导出脱出委托单
         */
        function createExl_inner() {
            var id = "${trail.id}";
            //	 	var url = "http://localhost:8075/WebReport/ReportServer?reportlet=trail.cpt&id="+id+"";
            var url = "http://192.168.0.4:7080/report/ReportServer?reportlet=gtimp/trail.cpt&id="
                      + id + "";
            window.open(url);
        }
    </script>

</head>
<body>
<input id="identifyForSup" type="hidden" value="${identify }"/>
<input id="checkTypeInput" type="hidden" value="${checkType }">
<div>

    <fieldset id="supInfo" class="custom_trailer"
              style="float: left;margin-right: 10px; display: none;">
        <table class="custom_supplier" style="font-size:12px">
            <tr class=" ui-widget-header table_header">
                <th colspan=2>客户信息</th>
            </tr>
            <tr>
                <td class="labelTD_first" style="padding-top: 15px">公司名称：</td>
                <td class="dataTD_two" style="padding-top: 15px"><s:property
                        value="trail.shipper.company"/></td>
            </tr>
            <tr>
                <td class="labelTD_first">联&nbsp&nbsp系&nbsp&nbsp人：</td>
                <td><s:property
                        value="trail.shipper.name"/></td>
            </tr>
            <tr>
                <td class="labelTD_first">电&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp话：</td>
                <td class="dataTD_two"><s:property value="trail.shipper.phone"/></td>
            </tr>
            <tr>
                <td class="labelTD_first">传&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp真：</td>
                <td class="dataTD_two"><s:property value="trail.shipper.fax"/></td>
            </tr>
            <tr>
                <td class="labelTD_first" style="padding-bottom: 15px">
                    地&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp址：
                </td>
                <td class="dataTD_two" style="padding-bottom: 15px;padding-right:50px"><s:property
                        value="trail.shipper.address"/></td>
            </tr>
        </table>
    </fieldset>

    <fieldset id="customInfo" class="custom_trailer"
              style="float: left;margin-right: 10px; display: none;">

        <table class="custom_supplier" style="font-size:12px">

            <tr class=" ui-widget-header table_header">
                <th colspan=2>供应商信息</th>
            </tr>
            <tr>
                <td class="labelTD_first" style="padding-top: 15px">公司名称：</td>
                <td class="dataTD_two" style="padding-top: 15px"><s:property
                        value="trail.supCompany.name"/></td>
            </tr>
            <tr>
                <td class="labelTD_first">联&nbsp&nbsp系&nbsp&nbsp人：</td>
                <td><s:property
                        value="trail.supCompany.contactor"/></td>
            </tr>
            <tr>
                <td class="labelTD_first">电&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp话：</td>
                <td class="dataTD_two"><s:property value="trail.supCompany.phone"/></td>
            </tr>
            <tr>
                <td class="labelTD_first">传&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp真：</td>
                <td class="dataTD_two"><s:property value="trail.supCompany.fax"/></td>
            </tr>
            <tr>
                <td class="labelTD_first" style="padding-bottom: 15px">
                    地&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp址：
                </td>
                <td class="dataTD_two" style="padding-bottom: 15px;padding-right:50px"><s:property
                        value="trail.supCompany.address"/></td>
            </tr>
        </table>
    </fieldset>
    <fieldset style="display: none;border: 0px;">
        <legend>业务实际委托人公司：</legend>
        <table class="dataTB">
            <tr>
                <td class="labelTD_1">公司名称/联系人：</td>
                <td class="dataTD"><s:property value="trail.shipper.company"/>/<s:property
                        value="trail.shipper.name"/></td>
            </tr>
            <tr>
                <td class="labelTD_1">地址：</td>
                <td class="dataTD"><s:property value="trail.shipper.address"/></td>
                <td class="labelTD_1">电话：</td>
                <td class="dataTD"><s:property value="trail.shipper.phone"/></td>
                <td class="labelTD_1">传真：</td>
                <td class="dataTD"><s:property value="trail.shipper.fax"/></td>
            </tr>
        </table>
    </fieldset>

    <fieldset class="custom_trailer">
        <table class="dataTB custom_supplier">
            <tr class=" ui-widget-header ui-corner-top table_header">
                <th colspan=2>
                    <span class="labelTD_1">业务编号：</span>
                    <span class="dataTD"><s:property value="trail.businessId"/></span>
                </th>
            </tr>
            <tr>
                <td class="labelTD_1" style="padding-top: 15px">
                    PI&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp号：
                </td>
                <td class="dataTD" style="padding-top: 15px"><s:property value="trail.pi"/></td>
            <tr>
            <tr>
                <td class="labelTD_1">柜&nbsp&nbsp总&nbsp&nbsp计：</td>
                <td class="dataTD"><span><s:iterator
                        value="containerTotle" var="size_type">
                    <s:property value="value"/>X
                    <s:property value="key"/>
                    <s:if test="!#size_type.isLast">/</s:if>
                </s:iterator></span></td>
            </tr>
            <!-- 			<tr> -->
            <!-- 				<td class="dataTD"><font color="red">点击柜号可以查询详细拖车出入闸信息</font></td> -->
            <!-- 			</tr> -->

            <td class="labelTD_1">报关票数：</td>
            <td class="dataTD"><s:property value="trail.declarationCount"/></td>
            </tr>
            <tr>
                <td>&nbsp</td>

            </tr>
            <tr>
                <td style="padding-bottom: 15px">&nbsp</td>

            </tr>
        </table>
    </fieldset>
</div>
<br>
<div class="clean"></div>
<fieldset style="border: 0px;" class="custom_trailer ">

    <table class="dataTB custom_supplier" rules="rows">
        <tr class=" ui-widget-header">
            <th colspan="7" class="ui-jqgrid-title">
                装运地点信息：
            </th>
        </tr>
        <tr style="background-color: #E4E2E2;text-align: left;"
            class="ui-state-default ui-th-column ui-th-ltr">
            <td class="table_box" width="10%" style="border: 0px solid;">订舱单号S/O</td>
            <td class="table_box" width="10%" style="border: 0px solid;">柜号</td>
            <td class="table_box" width="10%" style="border: 0px solid;">封条号</td>
            <!-- 		<td width="35%" style="border: 1px solid;">装柜地点id</td> -->
            <td class="table_box" width="35%" style="border: 0px solid;">装柜地点</td>
            <td class="table_box" width="15%" style="border: 0px solid;">联系方式</td>
            <td class="table_box" width="12%" style="border: 0px solid;">预约拖车时间</td>
            <td class="table_box" width="8%" style="border: 0px solid;">毛重(KG)</td>
            <!-- 		<td width="5%" style="border: 1px solid;">附件</td> -->
        </tr>
        <s:iterator value="ctAddressDTOList" var="ctAddress" status="st">
            <tr>
                <td class="dataTD labelTD_1 labelTD_12" align="left"><s:property
                        value="#ctAddress.container.so"/></td>
                    <%-- 		<td class="dataTD labelTD"><a href="javascript:{queryByCn(<s:property value="#ctAddress.container.carMsg.id"/>);}">MRKU9702716</a></td> --%>
                <!-- 		<td class="dataTD labelTD_1" align="left"><a href="javascript:{queryByCn('402881e544854ef701448b0988520012');}">MRKU9702716</a></td> -->
                <td class="dataTD labelTD_1 labelTD_12" align="left"><a
                        href="javascript:{queryByCn('<s:property value="#ctAddress.container.carMsg.id"/>');}"><s:property
                        value="#ctAddress.container.containerNo"/></a></td>
                <td class="dataTD labelTD_1 labelTD_12" align="left"><s:property
                        value="#ctAddress.container.seal"/></td>

                <td class="dataTD labelTD_1 labelTD_12">
                    <table>
                        <s:iterator value="#ctAddress.goodAddresses" var="gaddress">
                            <tr>
                                <td class="">
                                    <table>
                                        <tr>
                                            <td class="dataTD">
                                                <s:property
                                                        value="#gaddress.contacter.city"/><s:property
                                                    value="#gaddress.contacter.area"/><s:property
                                                    value="#gaddress.contacter.town"/><s:property
                                                    value="#gaddress.contacter.address"/>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </s:iterator>
                    </table>
                </td>
                <td class="dataTD labelTD_1 labelTD_12">
                    <table>
                        <s:iterator value="#ctAddress.goodAddresses" var="gaddress">
                            <tr>
                                <td class="">
                                    <table>
                                        <tr>
                                            <td class="dataTD"><s:property
                                                    value="#gaddress.contacter.name"/>/<s:property
                                                    value="#gaddress.contacter.phone"/></td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </s:iterator>
                    </table>
                </td>
                <td class="dataTD labelTD_1 labelTD_12">
                    <table>
                        <s:iterator value="#ctAddress.goodAddresses" var="gaddress">
                            <tr>
                                <td class="">
                                    <table>
                                        <tr>
                                            <td class="dataTD"><s:property
                                                    value="#gaddress.zhDate"/></td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </s:iterator>
                    </table>
                </td>
                <td class="dataTD labelTD_1 labelTD_12" align="center"><span
                        id="checkGoodGw_<s:property value="#st.index"/>"
                        style='cursor: pointer;'
                        onclick="checkGoodGw('<s:property
                                value="#ctAddress.container.containerNo"/>','<s:property
                                value="#ctAddress.container.id"/>','<s:property
                                value="#st.index"/>');">
							<font color="red">查看毛重</font>
					</span></td>
            </tr>
        </s:iterator>
        <%-- 	<tr><td class="labelTD">柜总计：</td><td><span style="margin-left:20px;"><s:iterator value="containerTotle" var="size_type"><s:property value="value"/>X<s:property value="key" /><s:if test="!#size_type.isLast">/</s:if> </s:iterator></span></td></tr> --%>
    </table>
</fieldset>

<br>
<fieldset style="border: 0px;">
    <legend>操作选项</legend>
    <table class="dataTD">
        <tr>
            <td class="dataTD" width="20%"><font color="red">SO文件和放柜通知：</font></td>
            <td class="dataTD">
                <s:if test="trail.soDoc==null">
                    没有文件下载
                </s:if>
                <s:else>
                    <a href="download?attachment.id=<s:property value="trail.soDoc.id"/>"
                       target="_blank">
                        <img style="vertical-align: middle; cursor: pointer;"
                             src='../img/fileDownload.png'/>
                    </a>
                </s:else>
            </td>
            <td></td>
            <td>
                <button ID="bizModifyBtn" onclick="bizModify();" class="custom_btnss">修改业务</button>
                <button ID="bizConfirmBtn" onclick="bizConfirm();" class="custom_btnss">提交业务
                </button>
                <button ID="trailVpassBtn" onclick="validatePass();">审核</button>
                <button ID="trailVrejectBtn" onclick="validateReject();">驳回业务</button>
                <!-- 			<a id='createExl' target='_blank' --> <%-- 			href="business-createBusiExl?trial.id=${trail.id}"><img --%>
                <!-- 				style="vertical-align: middle; vertical-align: middle\9; border: none;" -->
                <!-- 				src='../img/Orders.png' /></a> -->
                <button id="createExlBtn" onclick="createExl();"
                        class="ui-button ui-widget ui-state-default ui-corner-all custom_btn">
                    外网用户导出委托单
                </button>
                <button id="createExlBtn1" onclick="createExl_inner();"
                        class="ui-button ui-widget ui-state-default ui-corner-all custom_btn">
                    内网用户导出委托单
                </button>
                <button id="returnBtn" onclick="trailDetailReturnBack()"
                        class="ui-button ui-widget ui-state-default ui-corner-all custom_btn">返回
                </button>
            </td>
            <td></td>
        </tr>
    </table>
</fieldset>
<br>
<s:if test="cancelReasonList.size()>=1">
    <fieldset>
        <legend>业务单取消原因</legend>
        <table class="dataTD" width="100%" style="background-color: #DFF0F8;">
            <s:iterator value="cancelReasonList" status="st">
                <tr>
                    <td><s:property value="content"/></td>
                </tr>
                <tr>
                    <td align="right"><s:property value="cancelPerson"/>&nbsp;&nbsp;&nbsp;<s:date
                            name="cancelDate" format="yyyy-MM-dd hh:mm:ss"/></td>
                </tr>
            </s:iterator>
        </table>
    </fieldset>
</s:if>
<br>
<s:if test="rejectContentList.size()>=1">
    <fieldset>
        <legend>业务单驳回原因</legend>
        <table class="dataTD" width="100%" style="background-color: #DFF0F8;">
            <s:iterator value="rejectContentList" status="rc">
                <tr>
                    <td><s:property value="#rc.index+1"/>、<s:property
                            value="content"/></td>
                </tr>
                <tr>
                    <td align="right"><s:property value="rejectPerson"/>&nbsp;&nbsp;&nbsp;<s:date
                            name="rejectDate" format="yyyy-MM-dd hh:mm:ss"/></td>
                </tr>
            </s:iterator>
        </table>
    </fieldset>
</s:if>
</body>
</html>
